﻿using System.IO;
using System.Reflection;

namespace AmiCheckin.Code.Util
{
    public class PathUtil
    {
        public static string AppDirectory =>
            InitDir(Path.Combine(Directory.GetCurrentDirectory(), "config", "Ami签到"));

        public static string SelfPath =>
            Path.Combine(Assembly.GetExecutingAssembly().Location);

        public static string ConfigPath =>
            InitFile(Path.Combine(AppDirectory, "config.json"));

        public static string UserDataPath(long userid) =>
            InitFile(Path.Combine(AppDirectory, "datas", $"{userid}.ini"));

        public static string SqlDataPath(long userid) =>
            InitFile(Path.Combine(AppDirectory, "data.db"));

        public static string InitDir(string dir)
        {
            if (Directory.Exists(dir) is false)
            {
                Directory.CreateDirectory(dir);
            }

            return dir;
        }

        public static string InitFile(string path)
        {
            InitDir(Path.GetDirectoryName(path));

            if (File.Exists(path) is false)
            {
                File.Create(path).Close();
            }

            return path;
        }
    }
}